//
//  PhotoCollectionView.m
//  项目1 CLCMovie
//
//  Created by huiwenjiaoyu on 15/7/23.
//  Copyright (c) 2015年 CLC. All rights reserved.
//

#import "PhotoCollectionView.h"

@implementation PhotoCollectionView

- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    
    if (self) {
        NSLog(@"%ld",self.index);
        [self _creatCell];
       
    }
    
    return self;
}

- (void)setIndex:(NSInteger)index
{
    _index = index;
    self.contentOffset = CGPointMake(self.bounds.size.width*_index, 0);


}

- (void)_creatCell
{
    self.delegate = self;
    self.dataSource = self;
    
    [self registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"photoCell"];
}


//设置Cell
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return [_dataArray count];

}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
//    [self reloadData];
}

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photoCell" forIndexPath:indexPath];
    
    ImageModal* modal = self.dataArray[indexPath.row];
    NSString* url = [modal image];
    cell.imageURL = url;
    
    return cell;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
